﻿using System;
using System.Web;
using ManagedUIFlow.Application;
using Moq;
using Xunit;

namespace ManagedUIFlow.Specs.Application
{
    public class AppHttpHandlerSpecs
    {
        [Fact]
        public void ConstructorDoesNothing()
        {
            new AppHttpHandler();
        }

        [Fact]
        public void VerifyAndProcessRequestWithNullHandlerThrows()
        {
            var handler = new PublicMvcHttpHandler();

            Assert.Throws<ArgumentNullException>(() => handler.PublicVerifyAndProcessRequest(null, null));
        }

        public void ProcessRequestCallsExecute()
        {
            var handler = new PublicMvcHttpHandler();
            var mockTargetHandler = new Mock<IHttpHandler>();
            mockTargetHandler.Setup(h => h.ProcessRequest(It.IsAny<HttpContext>())).Verifiable();

            handler.PublicVerifyAndProcessRequest(mockTargetHandler.Object, null);

            mockTargetHandler.Verify();
        }

        private sealed class PublicMvcHttpHandler : AppHttpHandler
        {
            public void PublicVerifyAndProcessRequest(IHttpHandler httpHandler, HttpContextBase httpContext)
            {
                VerifyAndProcessRequest(httpHandler, httpContext);
            }
        }
    }
}
